package gui;
import processing.core.PApplet;
import processing.core.PConstants;

public class Button extends Widget {
	
	// these make a color palette
    // use foreColor() and bkgndColor() for drawing.
    boolean pressed = false;
	int thetextsize = 10;
	float leading = (float)0.8;
	String label;
	  
	public Button(PApplet parentApplet, float[] r, Object... args) {
		super(parentApplet, r, args);
//	    neutralColor = neutral;
//	    activeColor = active;
	    highlightColor = Color.darken(activeColor);
	}

	protected void drawFace() {
	    pa.noStroke();
	    pa.fill(foreColor());
	    pa.rectMode(PConstants.CORNER);
	    pa.rect(x0, y0, width, height);
	}
	  
	protected void drawName() {
	    pa.fill(bkgndColor());
	    pa.textAlign(PConstants.CENTER);
	    pa.textSize(thetextsize);
	    pa.textLeading(leading*thetextsize);
	    pa.text(label, x0 + width/2, y0 + height/2 + thetextsize/2);
	}
	
	protected int foreColor() {
	    if (pressed) {
	      return(highlightColor);
	    } else if (over()) {
	      return(activeColor);
	    } else {
	      return(neutralColor);
	    }
	  }
	  
	  private int bkgndColor() {
	    return backgroundColor;
	  }
	  
	  public void draw() {
	      drawFace();
	      drawName();
	  }
	  		  
	  public void mousePressed() {
		// If mouse pressed over button, flip the button state.
		pressed = !pressed;  
	  }
}
